package com.ruoyi.project.system.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.MiddleTableData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.system.mapper.TShortanswerMapper;
import com.ruoyi.project.system.domain.TShortanswer;
import com.ruoyi.project.system.service.ITShortanswerService;

/**
 * 简答题库Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-05-09
 */
@Service
public class TShortanswerServiceImpl implements ITShortanswerService 
{
    @Autowired
    private TShortanswerMapper tShortanswerMapper;

    /**
     * 查询简答题库
     * 
     * @param shortanswerId 简答题库ID
     * @return 简答题库
     */
    @Override
    public TShortanswer selectTShortanswerById(Integer shortanswerId)
    {
        return tShortanswerMapper.selectTShortanswerById(shortanswerId);
    }

    /**
     * 查询简答题库列表
     * 
     * @param tShortanswer 简答题库
     * @return 简答题库
     */
    @Override
    public List<TShortanswer> selectTShortanswerList(TShortanswer tShortanswer)
    {
        return tShortanswerMapper.selectTShortanswerList(tShortanswer);
    }

    /**
     * 新增简答题库
     * 
     * @param tShortanswer 简答题库
     * @return 结果
     */
    @Override
    public int insertTShortanswer(TShortanswer tShortanswer)
    {
        tShortanswer.setCreateTime(DateUtils.getNowDate());
        return tShortanswerMapper.insertTShortanswer(tShortanswer);
    }

    /**
     * 修改简答题库
     * 
     * @param tShortanswer 简答题库
     * @return 结果
     */
    @Override
    public int updateTShortanswer(TShortanswer tShortanswer)
    {
        return tShortanswerMapper.updateTShortanswer(tShortanswer);
    }

    /**
     * 批量删除简答题库
     * 
     * @param shortanswerIds 需要删除的简答题库ID
     * @return 结果
     */
    @Override
    public int deleteTShortanswerByIds(Integer[] shortanswerIds)
    {
        deleteMiddle(shortanswerIds[1],shortanswerIds[0]);
        return tShortanswerMapper.deleteTShortanswerByIds(shortanswerIds);
    }

    /**
     * 删除简答题库信息
     * 
     * @param shortanswerId 简答题库ID
     * @return 结果
     */
    @Override
    public int deleteTShortanswerById(Integer shortanswerId)
    {
        return tShortanswerMapper.deleteTShortanswerById(shortanswerId);
    }

    @Override
    public int addMiddle(Integer  subject_id ,Integer multiSel_id) {
        MiddleTableData middleTableData = new MiddleTableData();
        return tShortanswerMapper.addMiddle(middleTableData.FZMap(subject_id,multiSel_id));
    }

    @Override
    public int updateMiddle(Integer  subject_id ,Integer multiSel_id,String courseName) {
        MiddleTableData middleTableData = new MiddleTableData();
        Map map = middleTableData.FZMap(subject_id, multiSel_id);
        map.put("courseName",courseName);
        return tShortanswerMapper.updateMiddle(map);
    }

    @Override
    public int deleteMiddle(Integer  subject_id ,Integer multiSel_id) {

        MiddleTableData middleTableData = new MiddleTableData();
        return tShortanswerMapper.deleteMiddle(middleTableData.FZMap(subject_id,multiSel_id));
    }
}
